const {
  zmfAccountInfoCollection
} = require('../../../common/constants')
const {
  ERROR
} = require('../../../common/error')

/**
 * 新增账户信息
 * @param {Object}  params
 * @param {String}  params.uid     用户id
 * @param {String}  params.text2audio_words     文本转语音字数
 */
module.exports = async function (params = {}) {
  const schema = {
	uid: 'string',
    type: {
      required: true,
      type: 'string'
    },
	source: {
	  required: true,
	  type: 'number'
	},
	create_date: {
	  required: true,
	  type: 'number'
	},
	expire_date: {
	  required: true,
	  type: 'number'
	},
	words: {
	  required: true,
	  type: 'number'
	},
	used: {
	  required: true,
	  type: 'number'
	},
	use_up_mark: {
	  required: true,
	  type: 'boolean'
	}
  }
  
  this.middleware.validate(params, schema)
  
  const {
	  uid,
	  type,
	  source,
	  create_date,
	  expire_date,
	  words,
	  used,
	  use_up_mark
  } = params
  
  // 数据
  const data = {
	uid,
	type,
	source,
	create_date,
	expire_date,
	words,
	used,
	use_up_mark
  }
  
  const accountInfoResp = await zmfAccountInfoCollection.add(data)
  return {
    errCode: 0,
    userRecord: accountInfoResp
  }
}
